angular.module("app", [])
.controller("DemoCtrl", ['$scope', function($scope){

  $scope.formData = [
    {
      fieldTypeId: 1,
      defaultValue: 'first name'
    },
    {
      fieldTypeId: 2,
      defaultValue: 'this is text area'
    },
    {
      fieldTypeId: 13,
      defaultValue: 'this is address'
    }
  ]
}])

.directive('magicField', function(){
  return {
    restrict: 'E',
    scope: {
      fieldTypeId: '<',
      Value: '=?ngModel'
    },
    template:"<div ng-include='tplUrl'></div>",
    link: function(scope, elem, attr) {
      if (scope.fieldTypeId == 1) {
        scope.tplUrl = 'tpl/input.html'
      } else if (scope.fieldTypeId == 2) {
        scope.tplUrl = 'tpl/textarea.html'
      } else {
        console.log(elem)
        scope.tplUrl = 'tpl/address.html'
      }
    },
  }
})


.directive('mfAddress', function(){
  return {
    templateUrl: 'tpl/mf-address.html',
    replace: true,
    scope: {
      addressInfo: '=?ngModel'
    },
    link: function($scope, $element, $attrs, mfController){
      console.log($scope)
    }
  }
})
